//
//  BIDActivityDetailFooterView.m
//  JuanChengOA
//
//  Created by mal on 2017/7/26.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDActivityDetailFooterView.h"
#import "BIDShowPhotoViewII.h"

@interface BIDActivityDetailFooterView()<UIWebViewDelegate, BIDShowPhotoViewIIDelegate>

@end

@implementation BIDActivityDetailFooterView
@synthesize webView;
@synthesize showPhotoView;
@synthesize delegate;

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)awakeFromNib
{
    [super awakeFromNib];
    showPhotoView.delegate = self;
}

- (void)setImgArr:(NSArray *)imgArr
{
    if(!imgArr)
    {
        _heightForShowPhotoViewConstraint.constant = 0;
    }
    else
    {
        [showPhotoView adjustLayoutWithImgPathArr:imgArr];
        _heightForShowPhotoViewConstraint.constant = showPhotoView.frame.size.height;
    }
    
    [self setNeedsLayout];
    [self layoutIfNeeded];
    CGRect footerViewFrame = self.frame;
    footerViewFrame.size.height = CGRectGetMaxY(showPhotoView.frame)+10;
    self.frame = footerViewFrame;
    [delegate updateFooterView];
}

- (void)loadContent:(NSString *)content
{
    [webView loadHTMLString:content baseURL:nil];
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView1
{
    CGFloat webViewHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
    webViewHeight = webView.scrollView.contentSize.height;
    _heightForWebViewConstraint.constant = webViewHeight;
    [self setNeedsLayout];
    [self layoutIfNeeded];
    //
    CGRect footerViewFrame = self.frame;
    footerViewFrame.size.height = CGRectGetMaxY(showPhotoView.frame)+10;
    self.frame = footerViewFrame;
    [delegate updateFooterView];
}

#pragma mark - BIDShowPhotoViewIIDelegate
- (void)showPhotoAtIndex:(NSInteger)index withImgArr:(NSArray *)imgArr
{
    [delegate showPhotoAtIndex:index withImgArr:imgArr];
}

@end
